package com.light.springboot.base.jpa.repostitory.support;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

    EntityManager getEntityManager();

    T findOne(ID id, LockModeType lockMode);

    T findOne(Specification<T> spec, LockModeType lockMode);

    List<T> findTop(int top, Specification<T> spec, Sort sort);

    List<T> findTop(int top, Specification<T> spec, Sort sort, LockModeType lockMode);

    <S extends T> S update(S entity);

    //<T> List<T> nativeSqlResultDTO(Class<T> dtoClass, String sql, final Map<String, Object> params);

    <T> List<T> nativeSqlResult(String sql, final Map<String, Object> params);

    int updateByHQL(String hql, Map<String, Object> parameters);

    int updateNativeSql(String sql, Map<String, Object> parameters);


    public HashMap<String, Object> sqlQuery(String queryString, String countSql, Map<String, ?> values, int offset, int limit, String countName, String rowsName);

    public List<T> sqlQuery(String queryString, Map<String, ?> values);

    public List<T> sqlQuery(String queryString, Object... values);

    public HashMap<String, Object> retrieve(String queryString, String countHql, Map<String, ?> values, int offset, int limit, String countName, String rowsName);
}